package com.itheima.googleplay9.holder;

import android.text.format.Formatter;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.itheima.googleplay9.R;
import com.itheima.googleplay9.api.Url;
import com.itheima.googleplay9.bean.AppInfo;
import com.itheima.googleplay9.global.GooglePlayApp;
import com.itheima.googleplay9.global.ImageLoaderOptions;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import butterknife.Bind;

/**
 * Created by lxj on 2016/5/24.
 */
public class HomeHolder extends BaseHolder<AppInfo> {
    @Bind(R.id.iv_icon)
    ImageView ivIcon;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.rb_star)
    RatingBar rbStar;
    @Bind(R.id.tv_size)
    TextView tvSize;
    @Bind(R.id.tv_des)
    TextView tvDes;
    @Override
    protected View initHolderView() {
        View view = View.inflate(GooglePlayApp.context, R.layout.adapter_home, null);
        return view;
    }

    @Override
    public void bindData(AppInfo appInfo) {
        tvName.setText(appInfo.getName());
        tvSize.setText(Formatter.formatFileSize(GooglePlayApp.context, appInfo.getSize()));
        tvDes.setText(appInfo.getDes());
        rbStar.setRating(appInfo.getStars());

        //加载图片
        ImageLoader.getInstance().displayImage(Url.IMAGE_PREFIX + appInfo.getIconUrl(),
                ivIcon, ImageLoaderOptions.round_options);
    }
}
